/**
 * 
 */
package export;

import java.io.File;
import java.util.ArrayList;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

/**
 * This class provides methods for the export of result to an exel file.
 * @author Kevin Wagner
 * @version 1.0
 */
public class XLSExport {
	

	/**
	 * Exports the given result to the file result.xls.
	 * 
	 * @param result
	 * @throws Exception 
	 */
	public static void exportResult(ArrayList<double[]> result) throws Exception {
		WritableWorkbook workbook = Workbook.createWorkbook(new File("result.xls"));
		WritableSheet dataSheet = workbook.createSheet("data", 0);
		Label l=new Label(0, 0, "Gen");
		dataSheet.addCell(l);
		l=new Label(1, 0, "best");
		dataSheet.addCell(l);
		l=new Label(2, 0, "worst");
		dataSheet.addCell(l);
		l=new Label(3, 0, "mean");
		dataSheet.addCell(l);
		l=new Label(4, 0, "Std");
		dataSheet.addCell(l);
		for(int i=0;i<result.size();i++){
			Number n=new jxl.write.Number(0, i+1, i);
			dataSheet.addCell(n);
			for(int j=0; j<result.get(i).length;j++){
				n=new Number(j+1, i+1, result.get(i)[j]);
				dataSheet.addCell(n);
			}
		}
		workbook.write();
		workbook.close();
	}

}
